<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8" />
        <title>12.computed重写姓名案例</title>
        <!-- 引入Vue -->
        <script type="text/javascript" src="../js/vue.js"></script>
    </head>
    <body>
        <!-- 准备好一个容器-->
        <div id="app">
            姓：<input type="text" v-model="firstname" /><br/><br/><br/>
            名：<input type="text" v-model="lastname" /><br/><br/><br/>
            <h1>全名：{{fullname}}</h1>
        </div>
    </body>

    <script type="text/javascript">
        //阻止 vue 在启动时生成生产提示。
        Vue.config.productionTip = false
        let vm = new Vue({
            el:"#app",
            data:{
                firstname:'zhang',
                lastname:'san'
            },
            computed:{
                fullname(){
                    let {firstname,lastname} = this;
                    //异步
                    setTimeout(()=>{
                        return firstname[0].toUpperCase()+firstname.slice(1)+"-"+lastname[0].toUpperCase()+lastname.slice(1); 
                    },2000);

                   // return firstname[0].toUpperCase()+firstname.slice(1)+"-"+lastname[0].toUpperCase()+lastname.slice(1); 

                }
            }
        })

        console.log(vm);
    </script>
</html>